import { Constants } from '../constants'
import { DataTypes, Sequelize } from 'sequelize'
import { BaseModel, BaseModelAttribute } from './baseModel'
import { ModelUtils } from './modelUtils'
interface BorrowingAttribute extends BaseModelAttribute {
  borrower: string
  amount: number
  estimatedRepaymentDate: Date
  actualRepaymentDate: Date
  date: Date
}
export class Borrowing extends BaseModel<BorrowingAttribute> {
  borrower: string
  amount: number
  estimatedRepaymentDate: Date
  actualRepaymentDate: Date
  date: Date
}
export class BorrowingInit {
  static init(sequelizeInstance: Sequelize) {
    Borrowing.init(ModelUtils.appendPublicFields({
      borrower: { type: DataTypes.STRING, allowNull: false, comment: '分类名' },
      amount: { type: DataTypes.DECIMAL, allowNull: false, comment: Constants.amount },
      estimatedRepaymentDate: { type: DataTypes.DATE, allowNull: true, comment: '预计还款日期' },
      actualRepaymentDate: { type: DataTypes.DATE, allowNull: true, comment: '实际还款日期' },
      date: { type: DataTypes.DATE, allowNull: false, comment: Constants.date }
    }), ModelUtils.appendTablePublicProperties('borrowing', sequelizeInstance, '借出表'))
  }
}